<script>

export default {
  name: 'LayoutComponent',
  data () {
    return {
      menuList: [
        { name: '首页', path: '/' },
        { name: '分类', path: '/category' },
        { name: '标签', path: '/tag' },
        { name: '时间轴', path: '/timeline' }
      ]
    }
  },
  props: ['activeIndex'],
  methods: {
    login () {
      this.$router.push('/login')
    }
  },
  created () {
    const href = this.$route.params.href || 'admin'
    this.menuList = this.menuList.map(item => {
      return {
        name: item.name,
        path: `/${href}${item.path}`
      }
    })
    sessionStorage.setItem('api', href)
  }
}
</script>

<template>
  <div class="content">
    <div class="header">
      <div class="nav">
        <nav>
          <router-link v-for="(item,index) in menuList" :key="index" :class="{active:index === activeIndex}" :to="item.path">{{ item.name }}</router-link>
        </nav>
        <div @click="login" class="btn">写博客</div>
      </div>
    </div>
    <div class="main">
      <slot/>
    </div>
    <div class="footer"></div>
  </div>
</template>

<style scoped lang="scss">
$viewWidth:1080px;
$headerAndFooterHeight:60px;

.content{
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  .header{
    height: $headerAndFooterHeight;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #ccc;
    .nav{
      height: 50px;
      width: $viewWidth;
      display: flex;
      align-items: center;
      justify-content: space-between;
      nav{
        height: 40px;
        display: flex;
        a{
          display: flex;
          height: 100%;
          width: 80px;
          align-items: center;
          justify-content: center;
          margin-right: 10px;
          color: #333;
          text-decoration: none;
          &.active,&:hover{
            border-bottom: 2px solid #91cd95;
          }
        }
      }
      .btn{
        height: 40px;
        width: 90px;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #91cd95;
        border-radius: 20px;
        cursor: pointer;
        &:hover{
          color: #fff;
          opacity: .8;
        }
      }
    }
  }
  .main{
    width: $viewWidth;
    margin: 0 auto;
    flex: 1;
    display: flex;
    padding-top: 10px;
  }
  .footer{
    height: $headerAndFooterHeight;
    background-color: blueviolet;
  }
}
</style>
